import axios from 'axios'

let newAxios = axios.create({
    //接口基础地址
    baseURL:"http://xawn.f3322.net:8012",
    timeout:36000
})

newAxios.interceptors.response.use(res => {
    if (res.status !== 200) {
        alert("登录已过期");
        location = "#/login";
        return;
    }
    return res;
}, err => {
    console.log("err", err);
    localStorage.removeItem("token");
    alert("登录已过期");
    location = "#/login";
});

// 请求拦截器
newAxios.interceptors.request.use(req => {
    // 设置token
    let token = localStorage.getItem("token");
    if (token) {
        req.headers.Authentication = token;
    }
    return req;
})

export default newAxios